#include <stdio.h>
#include <stdlib.h>
#include "sikle.h"

void SikleState_init(SikleState* ss, Lexer* lex)
{
  ss->word_pool = GramelPool_new(0x1000);
  ss->gramel_pool = GramelPool_new(0x1000);
  ss->string_pool = StringPool_new(0x1000);
  ss->exec_stack = ExecStack_new(0x1000);
  ss->dictionary = Dictionary_new();

  register_builtin_words(ss);
  register_librarys(ss);
} 

void sikle(char* filename)
{
  Lexer lex;
  SikleState ss;

  Lexer_init(&lex, filename);

  SikleState_init(&ss, &lex);
  
  translate_main(&ss, &lex);
  
  GramelPool_dump(ss.gramel_pool, ss.string_pool);
  GramelPool_dump(ss.word_pool, ss.string_pool);
  //StringPool_dump(ss.string_pool);
  
  exec_gramel_main(&ss);
}

int main(int argc, char** argv)
{
  if(argc != 2){
    printf("Usage: sikle filename\n");
    exit(1);
  }
  
  sikle(argv[1]);
    
  return 0;
}
